package com.diorsunion.hedge.io;

import com.diorsunion.hedge.dto.AccountSummary;
import com.diorsunion.hedge.dto.BorkerAccount;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;

import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;

/**
 * Created by custe on 2016/8/10.
 */
public abstract class BaseMessageHandler implements MessageHandler{
    //可以处理的数据类
    final Set<Class> classSet = Sets.newHashSet();

    final Map<String,Function<Serializable, Message>> functionMap = Maps.newHashMap();
    protected void putFunction(String name,Function<Serializable, Message> function,Class... classes){
        functionMap.put(name,function);
        if(classes!=null){
            for(Class clazz:classes){
                classSet.add(clazz);
            }
        }
    }

    @Override
    public Map<String, Function<Serializable, Message>> getFunctionMap() {
        return functionMap;
    }

    @Override
    public Set<Class> handlerClasses() {
        return classSet;
    }
}
